package com.huishen.edrivenew.bean;

import com.google.gson.Gson;
import com.huishen.edrivenew.base.BaseBean;
import com.huishen.edrivenew.util.TLog;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 预约学车点击日历具体某一天 教练约课详情统计
 * @author wu
 *
 */

public class CoaLessonInfoBean extends BaseBean {
    
    public CoachBean cohInfo;

    // 已预约的天数
    public List<LessInfoBean> stuLessonInfo;

    public LessBean less;
    
    
    
    public static BaseBean parseJson(JSONObject jsonObj) {
        Gson gson = new Gson();
        
        CoaLessonInfoBean bean = gson.fromJson(jsonObj.toString(), CoaLessonInfoBean.class);

        TLog.log("LessonLimitBean  " + bean.less.lessonLimit.km2AM + " " + bean.less.lessonLimit.km2PM);

        return bean;
    }



    public List<LessInfoBean> groupBean = new ArrayList<LessInfoBean>();
    public List<LessInfoBean> listkm2 = new ArrayList<LessInfoBean>();
    public List<LessInfoBean> listkm3 = new ArrayList<LessInfoBean>();

    public void parseLesson() {
        LessInfoBean lesskm2 = new LessInfoBean("预约科目二");
        LessInfoBean lesskm3 = new LessInfoBean("预约科目三");

        if(less.lessonCount == null) {
            return;
        }

        for(LessInfoBean lessBean : less.lessonCount) {
            lessBean.kmcount = less.lessonLimit.getkmcount(lessBean.subject, lessBean.timeType);

            lessBean.setname();
            lessBean.status = 0;

            if(lessBean.count >= lessBean.kmcount) {
                // 约满
                lessBean.status = 2;
            }

            if(lessBean.subject == 2) {
                listkm2.add(lessBean);

                lesskm2.count += lessBean.count;
                lesskm2.kmcount += lessBean.kmcount;
            } else if(lessBean.subject == 3) {
                listkm3.add(lessBean);

                lesskm3.count += lessBean.count;
                lesskm3.kmcount += lessBean.kmcount;
            }
        }

        // 查找已约课
        for(LessInfoBean bean : stuLessonInfo) {
            if(bean.subject == 2) {
                for(LessInfoBean km2bean : listkm2) {
                    if(km2bean.timeType == bean.timeType) {
                        km2bean.status = 1;
                    }
                }
            } else if(bean.subject == 3) {
                for(LessInfoBean km3bean : listkm3) {
                    if(km3bean.timeType == bean.timeType) {
                        km3bean.status = 1;
                    }
                }
            }
        }

        groupBean.add(lesskm2);
        groupBean.add(lesskm3);
    }



}
